package com.fita.wechat.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.fita.entity.data.ShortUrl;
import com.fita.wechat.service.ShortUrlService;

/**
 * 
 * @author dan
 *
 */
@Controller
@RequestMapping("")
public class ShortUrlController {
    
    @Autowired
    private ShortUrlService shortUrlService;
    
    /**
     * 
     * @return
     */
    @RequestMapping("/{shortUrl}")
    public ModelAndView index(@PathVariable("shortUrl") String shortUrl) {
        ModelAndView modelAndView = new ModelAndView("short-url/index");
        
        ShortUrl url = shortUrlService.getByShortUrl(shortUrl);
        modelAndView.addObject("url", url);
        
        return modelAndView;
    }

}
